//
//  LoginRouter.swift
//  LeGou
//
//  Created by lxm on 2022/7/23.
//

import Foundation
class LoginRouter {
    // 路由
      static func initialize(navigator: NavigatorProtocol) {
          // 登录首页
          navigator.register("xm://main/Login/index") { url, values, context in
              return LoginVC()
          }
          
          // 第三方登录绑定手机
          navigator.register("xm://main/Login/bind_phone") { url, values, context in
              let vc = PhoneBindVC()
              if let context = context, let openId = JSON(context)["openId"].string {
                  vc.openId = openId
                  vc.nickname = JSON(context)["nickname"].stringValue
              }
              return vc
          }
          
          // 注册
          navigator.register("xm://main/Login/register") { url, values, context in
              return RegisterVC()
          }
          
          // 手机号输入
          navigator.register("xm://main/Login/phone_input") { url, values, context in
              return PhoneInputVC()
          }
          
          // 密码输入
          navigator.register("xm://main/Login/psd_input") { url, values, context in
              let vc = PsdInputVC()
              if let context = context, let phone = JSON(context)["phone"].string {
                  vc.phone = phone
              }
              return vc
          }
          
          // 验证码输入
          navigator.register("xm://main/Login/verify_input") { url, values, context in
              let vc = LoginCodeVerifyVC()
              if let context = context, let phone = JSON(context)["phone"].string {
                  vc.phone = phone
                  vc.openId = JSON(context)["openId"].string
                  vc.nickname = JSON(context)["nickname"].stringValue
              }
              return vc
          }
          
//          // 验证码输入
//          navigator.register("xm://main/Login/invite_ode_input") { url, values, context in
//              return InviteCodeInputVC()
//          }
          
          // 输入邀请信息
          navigator.register("xm://main/Login/invite_ode_input") { url, values, context in
              let vc = InviteCodeInputVC()
              if let context = context {
                  if let type = JSON(context)["type"].int {
                     vc.type = type
                  }
              }
              return vc
          }
          
          // 找回密码 type:0找回密码 1修改密码
          navigator.register("xm://main/Login/find_psd") { url, values, context in
              let vc = FindPsdVC()
              if let context = context {
                  if let phone = JSON(context)["phone"].string {
                     vc.phoneStr = phone
                  }
                  if let type = JSON(context)["type"].int {
                     vc.type = type
                  }
              }
              return vc
          }
      }
}

